#include "stdio.h"
#include "stdlib.h"
#include "time.h"

#define M 6
#define N 6 
void main()
{
	int i, j ,t=0;
	int x, y;
	int a[M][M];
	int b[50];
	srand((int)time(0));
	for(i=1; i<=M-1;i++)
	{
		for(j=1; j<=M-1; j++)
		{
			a[i][j] = t++;
		}
	}
	for(i=1; i<=M-1;i++)
	{
		for(j=1; j<=M-1; j++)
		{
			printf("%-3d",a[i][j]);
		}
		printf("\n");
	}
	system("PAUSE");
	t = 1;
	j = 0;
	for(i=1; i<=M-1;i++)
	{
		for(j=i; j<=M-1; j++)
		{
			b[t] = a[i][j];
			t++;
		}
	}
	for(i=1; i<t; i++)
	{
		printf("%-3d",b[i]);
	}
	printf("\n");
	while(1)
	{
		scanf("%d,%d",&x,&y);
		j = ((x-1)*(M-1))-((x-2)*(x-1)/2)+y-x+1;
		printf("\n%d\n",b[j]);
		system("PAUSE");
	}
}

